import axios from "axios"
import nprogress from "nprogress"
import "nprogress/nprogress.css"
//引入Vuex
import store from "@/store"

export const request = axios.create({
    baseURL:process.env.VUE_APP_API,
    timeout:10000,
})

request.interceptors.request.use((config)=>{
    // console.log(config);
    nprogress.start()
    //请求头添加临时id
    config.headers.userTempId = store.state.user.userId
    //请求添加token
    config.headers.token = store.state.user.token

    return config
},(error)=>{
    nprogress.done()
    return Promise.reject(error.message)
})

request.interceptors.response.use((response)=>{
    // console.log(response);
    nprogress.done()
    if(response.data.code!==200)return Promise.reject(response.data.message)
    return response.data.data
},(error)=>{
    nprogress.done()
    return Promise.reject(error.message)
})


